﻿Public Class frmQLLoaiMonAn
    Dim da As DataProvider
    Public Sub LoadDS()
        da = New DataProvider
        Dim sql = "select * from LOAIMONAN"
        dgvDSLoaiMonAn.DataSource = da.ShowData(sql)
    End Sub

    Private Sub frmQLLoaiMonAn_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadDS()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim sql = "INSERT INTO LOAIMONAN VALUES('" + txtMaLoai.Text + "'.'" + txtTenLoai.Text + "')"
        da = New DataProvider
        da.SqlExcuteNonQuery(sql)
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        Dim sql = "DELETE FROM LOAIMONAN WHERE MaLoaiMonAn = '" + txtMaLoai.Text + "'"
        da = New DataProvider
        da.SqlExcuteNonQuery(sql)
    End Sub

    Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
        Dim sql = "UPDATE LOAIMONAN SET TenLoaiMonAn = '" + txtTenLoai.Text + "'"
        da = New DataProvider
        da.SqlExcuteNonQuery(sql)
    End Sub

    Private Sub dgvDSLoaiMonAn_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dgvDSLoaiMonAn.SelectionChanged
        txtMaLoai.Text = dgvDSLoaiMonAn.CurrentRow.Cells(0).Value.ToString()
        txtTenLoai.Text = dgvDSLoaiMonAn.CurrentRow.Cells(1).Value.ToString()
    End Sub
End Class